package com.xique.park.controller.comm;

import com.xique.common.core.domain.R;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkGarage;
import com.xique.park.service.biz.service.IParkCarMngtypeBizService;
import com.xique.park.service.biz.service.IParkGarageLaneDevBizService;
import com.xique.park.service.biz.service.IParkLaneBizService;
import com.xique.park.service.biz.service.IParkUserBizService;
import com.xique.system.api.RemoteSystemDictService;
import com.xique.system.api.dto.SystemDictDataDTO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 公共controller
 * 主要用于返回前端id和名称匹配用到的列表
 */
@RestController
@RequestMapping("/comm")
public class CommController {

    @Autowired
    private IParkCarMngtypeBizService parkCarMngtypeBizService;

    @Autowired
    private IParkGarageLaneDevBizService parkGarageLaneDevBizService;

    @Autowired
    private IParkLaneBizService parkLaneBizService;

    @Autowired
    private RemoteSystemDictService remoteSystemDictService;


    /**
     * 根据字典类型，查询字典值列表
     */
    @GetMapping("/dict/list")
    public AjaxResult getDictData(@Param("dictType") String dictType) {
        R<List<SystemDictDataDTO>> res = remoteSystemDictService.getDictDataByType(dictType);
        if (null != res) {
            Map<String, Object> map = new HashMap<>(1);
            map.put("list", res.getData());
            return AjaxResult.success(map);
        } else {
            return AjaxResult.error("请联系管理员在后台录入开闸原因");
        }
    }

    /**
     * 查询某个车场下的所有管理类型列表
     */
    @GetMapping("/mngType/list")
    public AjaxResult getParkCarMngtypeList() {
        return parkCarMngtypeBizService.getParkCarMngtypeList();
    }

    /**
     * 查询车库列表
     */
    @GetMapping("/garage/list")
    public AjaxResult getParkGarageList(ParkGarage parkGarage) {
        return parkGarageLaneDevBizService.getGarageList(parkGarage);
    }

    /**
     * 查询通道列表
     */
    @PreAuthorize(hasPermi = "park:ipc:list")
    @GetMapping("/lane/list")
    public AjaxResult getParkLaneList() {
        return parkLaneBizService.getParkLaneList();
    }

}
